﻿using LD.BC;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LD.Tool
{
    public partial class ToolIOGroupMonitorFrm : FrmToolBase
    {
        public ToolIOGroupMonitorFrm()
        {
            InitializeComponent();
            this.Shown += ToolMoveFrm_Shown;
            this.btn_ok.Click += Btn_ok_Click;
        }

        private void Btn_ok_Click(object sender, EventArgs e)
        {
            if (this.cob_ioGruop.SelectedIndex >= 0)
            {

                IoMonitor ioMonitor = new IoMonitor()
                {
                    IoName = this.cob_ioGruop.Text,
                };
                this.TB_Tool.Param = Newtonsoft.Json.JsonConvert.SerializeObject(ioMonitor);
            }
        }

        private void ToolMoveFrm_Shown(object sender, EventArgs e)
        {
            Init();
        }
        private void Init()
        {
            //if (BcFactory.BC.IoGroup != null && BcFactory.BC.IoGroup.Count > 0)
            //{
            //    foreach (var item in BcFactory.BC.IoGroup)
            //    {
            //        this.cob_ioGruop.Items.Add(item.Name);
            //    }
            //}

            if (this.TB_Tool.Param == null)
                return;

            var tool = Newtonsoft.Json.JsonConvert.DeserializeObject<IoMonitor>(this.TB_Tool.Param);
            if (tool != null)
            {
                this.cob_ioGruop.Text = tool.IoName;
            }

        }
    }
}
